var h = $(window).height();
$(function () {
    $('.row-hoof').css({height: h, backgroundColor: '#d5dbe7'});
    $('.newStyle').css({height: h - 20 + 'px'});
    $(window).resize(function(){
        h = $(window).height();
        $('.row-hoof').css({height: h, backgroundColor: '#d5dbe7'});
        $('.newStyle').css({height: h - 20 + 'px'});
    })
    changekind(1,window.location.search.split('=')[1]);
})
function showDetail(qzbh,num){
    layer.open({
        type: 2,
        area: ['90%', h * 0.9 + 'px'],
        fixed: false, //不固定
        maxmin: false,
        content: 'layer/layer.html?' + qzbh + '&' + $('#userId').val()
    });
}
function nulls(item){
    var callback;
    if(item != null && item != undefined){
        callback = item;
    } else {
        callback = '无';
    }
    return callback;
}
//线索提交
function getInfo(){
    $.ajax({
        type: 'get',
        url: baseUrls + 'clueCheck/myClue',
        data: {checked: 0,userCode: $('#userCode').val(),pageIndex: 1,pageSize: 5},
        beforeSend: function(){
            Loading();
        },
        success: function(response){
            closeLoading();
            if(response.responseCode == '1000'){
                if(response.content.list.length > 0){
                    $('.firstContent-hoof').html('');
                    for(var i = 0; i < response.content.list.length; i++){
                        var clue = '',
                            status = '';
                        for(var j = 0; j < response.content.list[i].clueList.length; j++){
                            clue += '<span class="clueList"  onclick="showDetail(\''+ response.content.list[i].ajbh +'\',1)">' + nulls(response.content.list[i].clueList[j].qzmc)+'</span>';
                            status += '<span class="statusList">审核中</span>';
                        }
                        $('.firstContent-hoof').append('<li><div class="list list-hoof">' + (i+1) + '</div><div class="clueName clueName-hoof">' + response.content.list[i].ajmc + '</div><div class="clue clue-hoof">' + clue + '</div><div class="status status-hoof">' + status + '</div></li>');
                    }
                    for(var i = 0; i < $('.clue-hoof').length; i++){
                        $('.clue-hoof').eq(i).parent().children('.list-hoof').css({height: $('.clue-hoof').eq(i).height() + 'px',lineHeight: $('.clue-hoof').eq(i).height() + 'px'});
                        $('.clue-hoof').eq(i).parent().children('.clueName-hoof').css({height: $('.clue-hoof').eq(i).height() + 'px',lineHeight: $('.clue-hoof').eq(i).height() + 'px'});
                    }
                    $('#demo_pag1').bs_pagination({
                        totalPages: response.content.pages,
                        visiblePageLinks: 8,
                        currentPage: response.content.pageNum,
                        showGoToPage: false,
                        showRowsPerPage: false,
                        showRowsInfo: false,
                        showRowsDefaultInfo: false,
                        navListContainerClass: 'col-xs-12',
                        onChangePage: function (event, data) {
                            $.ajax({
                                type: 'get',
                                url: baseUrls + 'clueCheck/myClue',
                                data: {checked: 0,userCode: $('#userCode').val(),pageIndex: data.currentPage,pageSize: 5},
                                beforeSend: function(){
                                    Loading();
                                },
                                success: function(response){
                                    closeLoading();
                                    if(response.responseCode == '1000'){
                                        if(response.content.list.length > 0){
                                            $('.firstContent-hoof').html('');
                                            for(var i = 0; i < response.content.list.length; i++){
                                                var clue = '',
                                                    status = '';
                                                for(var j = 0; j < response.content.list[i].clueList.length; j++){
                                                    clue += '<span class="clueList"  onclick="showDetail(\''+ response.content.list[i].ajbh +'\')">' + nulls(response.content.list[i].clueList[j].qzmc)+'</span>';
                                                    status += '<span class="statusList">审核中</span>';
                                                }
                                                $('.firstContent-hoof').append('<li><div class="list list-hoof">' + (i+1) + '</div><div class="clueName clueName-hoof">' + response.content.list[i].ajmc + '</div><div class="clue clue-hoof">' + clue + '</div><div class="status status-hoof">' + status + '</div></li>');
                                            }
                                            for(var i = 0; i < $('.clue-hoof').length; i++){
                                                $('.clue-hoof').eq(i).parent().children('.list-hoof').css({height: $('.clue-hoof').eq(i).height() + 'px',lineHeight: $('.clue-hoof').eq(i).height() + 'px'});
                                                $('.clue-hoof').eq(i).parent().children('.clueName-hoof').css({height: $('.clue-hoof').eq(i).height() + 'px',lineHeight: $('.clue-hoof').eq(i).height() + 'px'});
                                            }
                                        }else{
                                            // $('.firstContent-hoof').css('display','none');
                                            $('#demo_pag1').html('');
                                        }
                                    }else{
                                        Msg();
                                    }
                                },
                                error: function(){
                                    closeLoading();
                                    Msg();
                                }
                            })
                        }
                    });
                }else{
                    $('.firstContent-hoof').html('');
                    $('#demo_pag1').html('');
                }
            }else{
                Msg();
            }
        },
        error: function(){
            closeLoading();
            Msg();
        }
    })
}
//线索审核记录
function historyInfo(){
    var length = Math.floor($('.secondContent-hoof').height() / 49);
    $.ajax({
        type: 'get',
        url: baseUrls + 'clueCheck/myClue',
        data: {checked: 1,userCode: $('#userCode').val(),pageIndex: 1,pageSize: length,xxylzd6: $('.Select').val()},
        beforeSend: function(){
            Loading();
        },
        success: function(response){
            closeLoading();
            if(response.responseCode == '1000'){
                if(response.content.list.length > 0){
                    $('.secondContent-hoof').html('');
                    for(var i = 0; i < response.content.list.length; i++){
                        var clue = '',
                            status = '',
                            num = 1;
                        for(var j = 0; j < response.content.list[i].clueList.length; j++){
                            if(response.content.list[i].clueList[j].checkstatus == '2'){
                                status += '<span class="statusList">通过</span>';
                                num = 1;
                            }else{
                                num = 2;
                                if(response.content.list[i].clueList[j].checkdesc != null){
                                    status += '<span class="statusList rejectSpan">驳回：'+ response.content.list[i].clueList[j].checkdesc +'</span>';
                                }else{
                                    status += '<span class="statusList rejectSpan">驳回</span>';
                                }
                            }
                            clue += '<span class="clueList"  onclick="showDetail(\''+ response.content.list[i].ajbh +'\', '+ num +')">' + nulls(response.content.list[i].clueList[j].qzmc)+'</span>';
                        }
                        $('.secondContent-hoof').append('<li><div class="list list-hoof">' + (i+1) + '</div><div class="clueName clueName-hoof">' + response.content.list[i].ajmc + '</div><div class="clue clue-hoof">' + clue + '</div><div class="status status-hoof">' + status + '</div></li>');
                    }
                    for(var i = 0; i < $('.clue-hoof').length; i++){
                        $('.clue-hoof').eq(i).parent().children('.list-hoof').css({height: $('.clue-hoof').eq(i).height() + 'px',lineHeight: $('.clue-hoof').eq(i).height() + 'px'});
                        $('.clue-hoof').eq(i).parent().children('.clueName-hoof').css({height: $('.clue-hoof').eq(i).height() + 'px',lineHeight: $('.clue-hoof').eq(i).height() + 'px'});
                    }
                    $('#demo_pag2').bs_pagination({
                        totalPages: response.content.pages,
                        visiblePageLinks: 8,
                        currentPage: response.content.pageNum,
                        showGoToPage: false,
                        showRowsPerPage: false,
                        showRowsInfo: false,
                        showRowsDefaultInfo: false,
                        navListContainerClass: 'col-xs-12',
                        onChangePage: function (event, data) {
                            $.ajax({
                                type: 'get',
                                url: baseUrls + 'clueCheck/myClue',
                                data: {checked: 1,userCode: $('#userCode').val(),pageIndex: data.currentPage,pageSize: length,xxylzd6: $('.Select').val()},
                                beforeSend: function(){
                                    Loading();
                                },
                                success: function(response){
                                    closeLoading();
                                    if(response.responseCode == '1000'){
                                        $('.secondContent-hoof').html('');
                                        for(var i = 0; i < response.content.list.length; i++){
                                            var clue = '',
                                                status = '';
                                            for(var j = 0; j < response.content.list[i].clueList.length; j++){
                                                clue += '<span class="clueList"  onclick="showDetail(\''+ response.content.list[i].ajbh +'\')">' + nulls(response.content.list[i].clueList[j].qzmc)+'</span>';
                                                if(response.content.list[i].clueList[j].checkstatus == '2'){
                                                    status += '<span class="statusList">通过</span>';
                                                }else{
                                                    if(response.content.list[i].clueList[j].checkdesc != null){
                                                        status += '<span class="statusList">驳回：'+ response.content.list[i].clueList[j].checkdesc +'</span>';
                                                    }else{
                                                        status += '<span class="statusList">驳回</span>';
                                                    }
                                                }
                                            }
                                            $('.secondContent-hoof').append('<li><div class="list list-hoof">' + (i+1) + '</div><div class="clueName clueName-hoof">' + response.content.list[i].ajmc + '</div><div class="clue clue-hoof">' + clue + '</div><div class="status status-hoof">' + status + '</div></li>');
                                        }
                                        for(var i = 0; i < $('.clue-hoof').length; i++){
                                            $('.clue-hoof').eq(i).parent().children('.list-hoof').css({height: $('.clue-hoof').eq(i).height() + 'px',lineHeight: $('.clue-hoof').eq(i).height() + 'px'});
                                            $('.clue-hoof').eq(i).parent().children('.clueName-hoof').css({height: $('.clue-hoof').eq(i).height() + 'px',lineHeight: $('.clue-hoof').eq(i).height() + 'px'});
                                        }
                                    }else{
                                        Msg();
                                    }
                                },
                                error: function(){
                                    closeLoading();
                                    Msg();
                                }
                            })
                        }
                    });
                }else{
                    $('.secondContent-hoof').html('');
                    $('#demo_pag2').html('');
                }
            }else{
                Msg();
            }
        },
        error: function(){
            closeLoading();
            Msg();
        }
    })
}
//指令提交
function myCommand() {
    var length = Math.floor(239 / 49);
    $.ajax({
        type: 'get',
        url: baseUrls + 'myCommand',
        data: {
            checked: 0,
            userid: $('#userId').val(),
            pageIndex: 1,
            pageSize: length
        },
        beforeSend: function(){
            Loading();
        },
        success: function(response){
            closeLoading();
            if(response.responseCode == '1000'){
                if(response.content.list.length > 0){
                    $('.threeContent-hoof').html('');
                    for(var i = 0; i < response.content.list.length; i++){
                        var status = '<span class="statusList">审核中</span>';
                        $('.threeContent-hoof').append('<li><div class="list list-hoof newLineHeight">' + (i+1) + '</div><div class="clueName clueName-hoof newLineHeight" style="cursor:pointer;" onclick="orderDetail(\''+ response.content.list[i].COMID +'\')">' + nulls(response.content.list[i].COMNAME) + '</div><div class="clue clue-hoof newLineHeight">' + nulls(response.content.list[i].COMCONTENT) + '</div><div class="status status-hoof">' + status + '</div><div class="status status-hoof"><button class="btn btn-primary" onclick="removeOrderList(this,\''+ response.content.list[i].COMID +'\',1)">删除</button></div></li>');
                    }
                    $('#demo_pag3').bs_pagination({
                        totalPages: response.content.pages,
                        visiblePageLinks: 8,
                        currentPage: response.content.pageNum,
                        showGoToPage: false,
                        showRowsPerPage: false,
                        showRowsInfo: false,
                        showRowsDefaultInfo: false,
                        navListContainerClass: 'col-xs-12',
                        onChangePage: function (event, data) {
                            $.ajax({
                                type: 'get',
                                url: baseUrls + 'myCommand',
                                data: {
                                    checked: 0,
                                    userid: $('#userId').val(),
                                    pageIndex: data.currentPage,
                                    pageSize: length
                                },
                                beforeSend: function(){
                                    Loading();
                                },
                                success: function(response){
                                    closeLoading();
                                    if(response.responseCode == '1000'){
                                        if(response.content.list.length > 0){
                                            $('.firstContent-hoof').html('');
                                            $('.threeContent-hoof').html('');
                                            for(var i = 0; i < response.content.list.length; i++){
                                                var status = '<span class="statusList">审核中</span>';
                                                $('.threeContent-hoof').append('<li><div class="list list-hoof newLineHeight">' + (i+1) + '</div><div class="clueName clueName-hoof newLineHeight" style="cursor:pointer;" onclick="orderDetail(\''+ response.content.list[i].COMID +'\')">' + nulls(response.content.list[i].COMNAME) + '</div><div class="clue clue-hoof newLineHeight">' + nulls(response.content.list[i].COMCONTENT) + '</div><div class="status status-hoof">' + status + '</div><div class="status status-hoof"><button class="btn btn-primary" onclick="removeOrderList(this,\''+ response.content.list[i].COMID +'\',1)">删除</button></div></li>');
                                            }
                                        }else{
                                            $('.firstContent-hoof').css('display','none');
                                            $('#demo_pag3').html('');
                                        }
                                    }else{
                                        Msg();
                                    }
                                },
                                error: function(){
                                    closeLoading();
                                    Msg();
                                }
                            })
                        }
                    });
                }else{
                    $('.threeContent-hoof').html('');
                    $('#demo_pag1').html('');
                }
            }else{
                Msg();
            }
        },
        error: function(){
            closeLoading();
            Msg();
        }
    })
}
//历史指令
function myCommandHistory(){
    var length = Math.floor($('.fourContent-hoof').height() / 49);
    $.ajax({
        type: 'get',
        url: baseUrls + 'myCommand',
        data: {
            checked: 1,
            userid: $('#userId').val(),
            sendtime: $('#select').val(),
            pageIndex: 1,
            pageSize: length
        },
        beforeSend: function(){
            Loading();
        },
        success: function(response){
            closeLoading();
            if(response.responseCode == '1000'){
                if(response.content.list.length > 0){
                    $('.fourContent-hoof').html('');
                    for(var i = 0; i < response.content.list.length; i++){
                        var status = '';
                        if(response.content.list[i].CHECKSTATUS == '1'){
                            status += '<span class="statusList">通过</span>';
                        }else{
                            if(response.content.list[i].CHECKDESC != null){
                                status += '<span class="statusList rejectSpan">驳回：'+ nulls(response.content.list[i].CHECKDESC) +'</span>';
                            }else{
                                status += '<span class="statusList rejectSpan">驳回</span>';
                            }
                        }
                        $('.fourContent-hoof').append('<li><div class="list list-hoof newLineHeight">' + (i+1) + '</div><div class="clueName clueName-hoof newLineHeight" style="cursor:pointer;" onclick="orderDetail(\''+ response.content.list[i].COMID +'\')">' + nulls(response.content.list[i].COMNAME) + '</div><div class="clue clue-hoof newLineHeight">' + nulls(response.content.list[i].COMCONTENT) + '</div><div class="status status-hoof">' + status + '</div><div class="status status-hoof"><button class="btn btn-primary" onclick="removeOrderList(this,\''+ response.content.list[i].COMID +'\',2)">删除</button></div></li>');
                    }
                    $('#demo_pag4').bs_pagination({
                        totalPages: response.content.pages,
                        visiblePageLinks: 8,
                        currentPage: response.content.pageNum,
                        showGoToPage: false,
                        showRowsPerPage: false,
                        showRowsInfo: false,
                        showRowsDefaultInfo: false,
                        navListContainerClass: 'col-xs-12',
                        onChangePage: function (event, data) {
                            $.ajax({
                                type: 'get',
                                url: baseUrls + 'myCommand',
                                data: {
                                    checked: 1,
                                    userid: $('#userId').val(),
                                    sendtime: $('#select').val(),
                                    pageIndex: data.currentPage,
                                    pageSize: length
                                },
                                 beforeSend: function(){
                                    Loading();
                                },
                                success: function(response){
                                    closeLoading();
                                    if(response.responseCode == '1000'){
                                        $('.fourContent-hoof').html('');
                                        for(var i = 0; i < response.content.list.length; i++){
                                            var status = '';
                                            if(response.content.list[i].CHECKSTATUS == '1'){
                                                status += '<span class="statusList">通过</span>';
                                            }else{
                                                if(response.content.list[i].CHECKDESC != null){
                                                    status += '<span class="statusList rejectSpan">驳回：'+ nulls(response.content.list[i].CHECKDESC) +'</span>';
                                                }else{
                                                    status += '<span class="statusList rejectSpan">驳回</span>';
                                                }
                                            }
                                            $('.fourContent-hoof').append('<li><div class="list list-hoof newLineHeight">' + (i+1) + '</div><div class="clueName clueName-hoof newLineHeight" style="cursor:pointer;" onclick="orderDetail(\''+ response.content.list[i].COMID +'\')">' + nulls(response.content.list[i].COMNAME) + '</div><div class="clue clue-hoof newLineHeight">' + nulls(response.content.list[i].COMCONTENT) + '</div><div class="status status-hoof">' + status + '</div><div class="status status-hoof"><button class="btn btn-primary" onclick="removeOrderList(this,\''+ response.content.list[i].COMID +'\',2)">删除</button></div></li>');
                                        }
                                    }else{
                                        Msg();
                                    }
                                },
                                error: function(){
                                    closeLoading();
                                    Msg();
                                }
                            })
                        }
                    });
                }else{
                    $('.fourContent-hoof').html('');
                    $('#demo_pag4').html('');
                }
            }else{
                Msg();
            }
        },
        error: function(){
            closeLoading();
            Msg();
        }
    })
}
//tab切换
function changekind(item,type){
    if(type){
        $('.title li').eq(type).addClass('active').removeClass('normal').siblings().addClass('normal').removeClass('active');
        if(type == 0){
            $('.commonExamine').eq(0).show();
            $('.commonExamine').eq(1).hide();
            if($('#roleEnName').val() == 'ptyh'){
                $('.myExamineFirst').css('display','block');
                $('.secondContent-hoof').css({height: h - $('.myExamineFirst').height() - 230 + 'px'});
                getInfo();
            }else{
                $('.myExamineFirst').css('display','none');
                $('.secondContent-hoof').css({minHeight: h - 230 + 'px'});
            }
            historyInfo();
        } else{
            $('.commonExamine').eq(0).hide();
            $('.commonExamine').eq(1).show();
            if($('#roleEnName').val() == 'ptyh'){
                $('.myOrderFirst').css('display','block');
                $('.fourContent-hoof').css({height: h - $('.myOrderFirst').height() - 230 + 'px'});
                myCommand();
            }else{
                $('.myOrderFirst').css('display','none');
                $('.fourContent-hoof').css({height: h - 230 + 'px'});
            }
            myCommandHistory();
        }
    }else{
        if($(item).hasClass('active')){
        }else{
            $(item).addClass('active').removeClass('normal');
            $(item).siblings().addClass('normal').removeClass('active');
            if($(item).index() == 0 || item == 1){
                $('.commonExamine').eq(0).show();
                $('.commonExamine').eq(1).hide();
                if($('#roleEnName').val() == 'ptyh'){
                    $('.myExamineFirst').css('display','block');
                    $('.secondContent-hoof').css({height: h - $('.myExamineFirst').height() - 230 + 'px'});
                    getInfo();
                }else{
                    $('.myExamineFirst').css('display','none');
                    $('.secondContent-hoof').css({height: h - 230 + 'px'});
                }
                historyInfo();
            } else{
                $('.commonExamine').eq(0).hide();
                $('.commonExamine').eq(1).show();
                if($('#roleEnName').val() == 'ptyh'){
                    $('.myOrderFirst').css('display','block');
                    $('.fourContent-hoof').css({height: h - $('.myOrderFirst').height() - 230 + 'px'});
                    myCommand();
                }else{
                    $('.myOrderFirst').css('display','none');
                    $('.fourContent-hoof').css({height: h - 230 + 'px'});
                }
                myCommandHistory();
            }
        }
    }
}
//删除指令
function removeOrderList(item,comid,num){ //1代表审核中的 2代表已审核
    $.ajax({
        type: 'post',
        cache: false,
        url: baseUrls + 'command/remove',
        data:{
            userid: $('#userId').val(),
            comid: comid
        },
        beforeSend: function(){
            Loading();
        },
        success: function(response){
            closeLoading();
            if(response.responseCode == '1000'){
                Msg('删除成功',1);
                if(num ==1){
                    myCommand();
                }else{
                    myCommandHistory();
                }
            }else{
                Msg('删除失败，请稍后在试，或联系管理员',5);
            }
        },
        error: function(){
            closeLoading();
            Msg('删除失败，请稍后在试，或联系管理员',5);
        }
    })
}